import subprocess

def run_adb_command(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output, error

# 使用 adb 命令获取当前屏幕的 XML 布局
output, error = run_adb_command("adb shell uiautomator dump")
output_pull, error_pull = run_adb_command("adb pull /sdcard/window_dump.xml")

# 将 XML 文件保存到本地
with open("window_dump.xml", "wb") as file:
    file.write(output_pull)

# 如果有错误信息，打印出来
if error:
    print("Error:", error.decode())
if error_pull:
    print("Error Pull:", error_pull.decode())
